package com.bosicloud.cmb.ibp.aws.adapter.controller;

import com.bosicloud.cmb.ibp.aws.adapter.commom.constant.UrlDefine;
import com.bosicloud.cmb.ibp.aws.adapter.service.impl.S3ServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestPart;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * @author Jack Peng / ziliang.peng@bosicloud.com
 */
@Slf4j
@RestController
@Api(value = "S3接口", description = "AWS S3接口")
public class S3Controller {

    @Autowired
    S3ServiceImpl s3Service;

    @ApiOperation(value = "上传文件")
    @PostMapping(value = UrlDefine.S3_UPLOAD, consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = { MediaType.TEXT_PLAIN_VALUE })
    public String upload(@RequestPart(value = "file") MultipartFile file) throws IOException {

        return s3Service.uploadFile(file.getOriginalFilename(), file.getBytes());

    }


}
